package com.qingmeng.applyjob.portal.controller;

import com.qingmeng.applyjob.common.api.CommonPage;
import com.qingmeng.applyjob.common.api.CommonResult;
import com.qingmeng.applyjob.portal.model.dto.AdvertisePublishParam;
import com.qingmeng.applyjob.portal.model.vo.AdvertiseListVo;
import com.qingmeng.applyjob.portal.model.vo.AdvertiseVo;
import com.qingmeng.applyjob.portal.service.AdvertiseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/advertise")
@Api(tags = "advertiseController" , description = "招聘接口")
public class AdvertiseController {

    @Autowired
    private AdvertiseService advertiseService;

    @ApiOperation("发布招聘")
    @PostMapping("/publishTask")
    private CommonResult<Integer> publishTask(@ApiParam("发布招聘时填写的招聘信息") @RequestBody AdvertisePublishParam advertisePublishParam){
        int result = advertiseService.publishTask(advertisePublishParam);
        if(result > 0){
            return CommonResult.success(result,"招聘发布成功");
        }
        return CommonResult.failed("招聘发布失败");
    }

    @ApiOperation("根据职位类型获取招聘列表（职位类型（1：实习 2：社招 3：校招）")
    @GetMapping("/advertiseList")
    private CommonResult<CommonPage<AdvertiseListVo>> advertiseList(@ApiParam("页码") @RequestParam(value = "pageNum" , defaultValue = "1") Integer pageNum,
                                                                    @ApiParam("每页包含条数") @RequestParam(value = "pageSize" , defaultValue = "5") Integer pageSize,
                                                                    @ApiParam("职位类型（1：实习 2：社招 3：校招") @RequestParam("workType") Integer workType){
        List<AdvertiseListVo> advertiseListVos = advertiseService.advertiseList(pageNum, pageSize,workType);
            if (advertiseListVos != null && advertiseListVos.size()>0){
                return CommonResult.success(CommonPage.restPage(advertiseListVos),"获取成功");
            }
            return CommonResult.failed("没有查询到相关数据");
    }

    @ApiOperation("获取招聘详情")
    @GetMapping("/getAdvertise")
    private CommonResult<AdvertiseVo> getAdvertise(@ApiParam("招聘id") @RequestParam(value = "advertiseId") Long advertiseId){
        AdvertiseVo advertise = advertiseService.getAdvertise(advertiseId);
        if (advertise != null){
            return CommonResult.success(advertise,"获取成功");
        }
        return CommonResult.failed("未查询到相关信息");
    }
}
